package com.sx.first.action;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.sx.first.biz.MaterialBiz;
import com.sx.first.model.Material;

@Controller
@Scope("prototype")
@Namespace("/material")
@Results({ @Result(name = "list", location = "list.jsp"), @Result(name = "add", location = "add.jsp"),
	@Result(name = "update", location = "update.jsp"), })
public class MaterialAction extends BaseAction {
	private List<Material> matList;
	private Material mat;
	private MaterialBiz materialBiz;
	
	@Action(value = "list")
	public String list(){
		matList = materialBiz.findAll();
		return "list";
	}
	
	@Action(value = "add")
	public String add(){
		return "add";
	}
	
	@Action(value = "doAdd")
	public String doAdd(){
		materialBiz.save(mat);
		return list();
	}
	
	@Action(value = "delete")
	public String delete(){
		materialBiz.delete(mat.getMatId());
		return list();
	}
	
	@Action(value = "update")
	public String update(){
		mat = materialBiz.findById(mat.getMatId());
		return "update";
	}
	
	@Action(value = "doUpdate")
	public String doUpdate(){
		materialBiz.update(mat);
		return list();
	}
	
	/***********************/
	
	public List<Material> getMatList() {
		return matList;
	}
	public void setMatList(List<Material> matList) {
		this.matList = matList;
	}
	public Material getMat() {
		return mat;
	}
	public void setMat(Material mat) {
		this.mat = mat;
	}
	public void setMaterialBiz(MaterialBiz materialBiz) {
		this.materialBiz = materialBiz;
	}
	
	

}
